package com.gem.day14.homework;

import java.io.File;

/**
 * 统计多层文件夹下文件和文件夹的数量
 */
public class Exercise2 {
	int countDirectory = 0;
	int countFile = 0;

	public static void main(String[] args) {
		Exercise2 demo = new Exercise2();
		demo.getFileAndDirectory(new File("F:\\文档"));
		System.out.println("目录文件数目为：" + demo.countDirectory);
		System.out.println("普通文件数目为：" + demo.countFile);
	}

	public void getFileAndDirectory(File file) {
		if (file.isDirectory()) {
			File[] files = file.listFiles();
			for (File fileIndex : files) {
				if (fileIndex.isDirectory()) {
					countDirectory++;
					getFileAndDirectory(fileIndex);

				} else {
					countFile++;
				}
			}
		}
	}
}